package Sort;

import java.util.Arrays;

public class BubbleSort {

    public void operation(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            boolean flag = false;
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    swap(arr, j, j +1);
                    flag = true;
                }
            }
            if (!flag) {
                break;
            }
        }
    }

    public void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = {2,4,5,6,87,6,5,3,2,3,45,56,7};

        BubbleSort bubbleSort = new BubbleSort();
        bubbleSort.operation(arr);
        System.out.println(Arrays.toString(arr));
    }
}
